import Deliver from "App/Models/Deliver";
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
export default class DeliversController {
  public async addDeliver(params: any){
      await Deliver.create(params);
  }

  /**
   * 查询待发货信息
   * @param ctx
   */
   async getDeliverData(ctx: HttpContextContract) {
        const params:any=ctx.request.body();
        const delivers = await Deliver.query().forPage(params.curPage,params.pageSize);
        const count = await Deliver.query().count("id");
        let countRes=count[0]['$extras']['count(`id`)'];
        return {result:delivers.map((deliver) => deliver.toJSON()),total:countRes};
   }

  /**
   * 删除
   * @param ctx
   */
   public async deleteDeliverData(ctx: HttpContextContract) {
        const params:any=ctx.request.body();
        let deliver=Deliver.query().where("id","in",params.ids);
        await deliver.delete();
   }
}
